import { httpUrl } from 'api/config';
import { ajaxPost } from 'api/axios';
import { changeDataType } from 'common/js/util';

export function getList(page = 1) {
	let url = `${httpUrl}/appservice/list`;
	
	let data = {
		page: page,
		rows: 10
	};
	
	return ajaxPost(url, changeDataType(data))
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function updateList(obj) {
	let url = `${httpUrl}/appservice/save`;
	
	let data = obj
	
	return ajaxPost(url, data)
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function deleteList(id) {
	let url = `${httpUrl}/comm/AppService/delete`;
	
	let data = {
		id: id
	}
	
	return ajaxPost(url, changeDataType(data))
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function startUp(arr) {
	let url = `${httpUrl}/appservice/startService`;
	
	let data = {
		serviceIds: arr
	}
	
	return ajaxPost(url, data)
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function shutDown(arr) {
	let url = `${httpUrl}/appservice/stopService`;
	
	let data = {
		serviceIds: arr
	}
	
	return ajaxPost(url, data)
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function getServiceList() {
	let url = `${httpUrl}/file/listIp`;

	let data = {}
	
	return ajaxPost(url, data)
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}

export function getDocumentList(service, documentUrl) {
	let url = `${httpUrl}/file/listfiles`;

	let data = {
		server: service,
		currentFile: documentUrl
	}
	
	return ajaxPost(url, changeDataType(data))
		.then(res => {
			return Promise.resolve(res)
		})
		.catch(res => {
			return Promise.reject(res)
		})
}
